import java.util.PriorityQueue;
import java.util.Timer;
import java.util.TimerTask;

public class Demo1 {
    public static void main(String[] args) {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("aaa");
            }
        },1000);
        System.out.println("=====");
    }
}
class Solution {
    public boolean checkValidGrid(int[][] grid) {
        if(grid[0][0] != 0) return false;
        PriorityQueue<int[]> queue = new PriorityQueue<>((a, b) -> {
            return a[0] - b[0];
        });
        for(int i=0; i<grid.length; i++){
            for(int j=0; j<grid[i].length; j++){
                queue.offer(new int[]{grid[i][j],i,j});
            }
        }
        int[] pre = queue.poll();
        while(!queue.isEmpty()){
            int[] cur = queue.peek();
            if(!isValid(pre,cur)){
                break;
            }
            queue.poll();
            pre = cur;
        }
        return queue.isEmpty();
    }
    /**
     prev[1]+prev[2]
     */
    boolean isValid(int[] prev, int[] cur){
        return prev[1] != cur[1] && prev[2] != cur[2]
                && Math.abs(prev[1]-cur[1])+Math.abs(prev[2]-cur[2]) == 3;
    }
}